package main

/*
#include <math.h>
#cgo LDFLAGS: -lm

struct point_t {
    double x,y;
};

struct circle_t {
    struct point_t p;
    double r;
};

double area(struct circle_t c) {
    return c.r * c.r * 3.1415926;
}

double distance(struct point_t p) {
    return sqrt(p.x*p.x + p.y * p.y);
}

int sum_of_array(int * int_arr, int arr_len) {
    int i;
    long sum = 0;
    for (i = 0; i < arr_len; i++) {
        sum =  sum + int_arr[i];
    }
    return sum;
}

int c_int_arr[] = {1,2,3,4,5};
*/
import "C"

import (
	"fmt"
)

func main() {
	var c C.struct_circle_t
	c.r = 10.3
	c.p.x = 3.1
	c.p.y = 4.2

	a := C.area(c)
	fmt.Printf("area of circle :%f\n", a)

	d := C.distance(c.p)
	fmt.Printf("distance to (0,0): %f\n", d)

	//数组求和
	ia := [...]C.int{1, 2, 3, 4, 5}
	s := C.sum_of_array(&ia[0], C.int(len(ia)))
	fmt.Printf("sum = %d\n", s)

	for i := 0; i < 5; i++ {
		fmt.Printf("c_int_arr[%d] = %d\n", i, C.c_int_arr[i])
	}
}
